﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication2.Filters
{
    public class QuanFilterAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //需求：1 获取当前url中的权限信息 /Home/Index
            string c = filterContext.RouteData.GetRequiredString("controller");
            string a = filterContext.RouteData.GetRequiredString("action");
            string ulr = "/" + c + "/" + a;
            //2 根据当前的用户获取所有的权限信息 {"/Home/About","Login/Index"}
            List<string> list = new List<string>()
            {
                "/Home/Index",
                "/Login/Index",
                "/Login/login"
            };
            //3 判断1是否在2中出现过;
            if (list.Contains(ulr) == false)
            {
                //3.1 如果没有就跳转页面
                filterContext.Result = new ViewResult()
                {
                    ViewName = "TiShi"
                };
            }
        }
    }
}